﻿#include "systemstateinfo.h"

SystemStateInfo::SystemStateInfo(QObject *parent)
	: ComponentBase(parent)
{
	m_name = u8"系统状态信息";
	m_errmsg = "";
	m_type = Component::component_systemInfo;
}

SystemStateInfo::~SystemStateInfo()
{
}

// 组件初始化处理函数
int SystemStateInfo::ComponentInit()
{
	return 0;
}
/*自检接口*/
bool SystemStateInfo::ComponentCheckSelfState()
{
	return true;
}
/*复位接口*/
bool SystemStateInfo::ComponentSelfReset()
{
	return true;
}

void SystemStateInfo::ResponseSystemState(int state)
{
	m_state = state;
}

// 命令执行接口
bool SystemStateInfo::ExcuteCmd(int cmd, const QByteArray& input, QByteArray& output)
{
	output.clear();
	SystemCmdType type = (SystemCmdType)cmd;
	switch (type) {
	case SystemCmdType::system_cmd_get_state:
		output = QString::number(m_state).toUtf8();
		break;
	case SystemCmdType::system_cmd_system_stop:
		SetErrmsg("手动停止");
		break;
	case SystemCmdType::system_cmd_System_reset:
		SetWarningmsg("手动复位");
		emit PublishSystemEvent((int)m_type, (int)ComponentEvent::system_event_reset);
		break;
	case SystemCmdType::system_cmd_System_start:
		emit PublishSystemEvent((int)m_type, (int)ComponentEvent::system_event_start);
		break;
	default:
		output = "错误的指令";
		return false;
		break;
	}

	return true;
}
